<?php


/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/**
 * @package	
 */
class HelpDeskViewConfig extends HelpDeskView 
{
	/**
	 * 
	 * 
	 */
	function display($tpl=null) 
	{
		$layout = $this->getLayout();
		switch(strtolower($layout))
		{
			case "define":
			case "view":
			case "form":
			case "default":
			default:
				$this->_default($tpl);
			  break;
		}
	}

	/**
	 * 
	 * @param $tpl
	 * @return unknown_type
	 */
	function _default($tpl=null) 
	{		
		$mainframe	= HelpDeskConfig::getApplication();
		$user 		= HelpDeskConfig::getUser();
		$database 	= HelpDeskConfig::getDBO();
		$model 		= $this->getModel();
		$app 		= HelpDeskConfig::getApplication();

		// check config		
			$config = &HelpDeskConfig::getInstance();
			$this->assignRef( 'config', $config );
			
        // Get data from the model
        	$filtered = array();
	        $items = $model->getData();
			for ($i=0; $i<count($items); $i++) 
			{
				$item = &$items[$i];
				// Check if they have an event
				if ($hasEvent = HelpDeskHelperTools::hasEvent( $item, 'onListConfigHelpDesk' )) {
					// add item to filtered array
					$filtered[] = $item;
				}
			}
			$items = $filtered;
			$this->assignRef( 'items_sliders', $items );
			
		// lists
			$lists = new HelpDeskObject();	
			$lists->fromname = $mainframe->getCfg( 'fromname' );
			$lists->mailfrom = $mainframe->getCfg( 'mailfrom' );
			$this->assignRef('lists', $lists);	

		// Add pane
			$sliders = HelpDeskPane::getInstance( 'sliders' );		
			$this->assignRef('sliders', $sliders);
			
		// set the required image
			$required = new stdClass();
			$required->text = HelpDeskText::_( 'Required' );
			$required->image = "<img src='".HelpDeskUrl::root()."/components/"._THISCOMPONENT."/images/required_16.png' alt='{$required->text}'>";
			$dispatcher = HelpDeskHelperPlugin::getInstance();
			$dispatcher->trigger( 'onSetRequiredImage', array( $required ) );
			$this->assignRef('required', $required );

		// set pagetitle
			$pagetitle  = HelpDeskText::_( 'Configuration' );
			$this->assignRef('pagetitle', $pagetitle );
			
		// Assign variables
			$this->assignRef('user', $user );
	        $this->assignRef('row', $config);
	        		
		// form
			$formAction = "index2.php";
			$this->assignRef( 'formAction' , $formAction );
			$validate = josSpoofValue();
			$formValidate = "<input type='hidden' name='{$validate}' value='1' />"; 
			$this->assignRef( 'formValidate' , $formValidate );
			$this->assignRef( 'formOption' , HelpDeskRequest::getVar( 'option' ) );
			$this->assignRef( 'formController' , $this->_name );
			$this->assignRef( 'formId' , $model->_id );
		
		parent::display($tpl);
		
	}
	
}